import SwiftUI

struct DetailBar: View {
    var proxy:GeometryProxy
    @Binding var isVideoReady: Bool  // 通过 Binding 传递 isVideoReady
    @Binding var item: MainPica  // 通过 Binding 传递 isVideoReady
    @Binding var speaker: Bool
    @Binding  var scrollOffset: CGFloat
    @Binding  var posterScale: CGFloat
    @Binding var isImageVisible: Bool
    @Binding var isVideoStarted: Bool
    @Binding var isVideoPlaying: Bool
    @Environment(\.dismiss) var dismiss
    @StateObject private var viewModelFav = FavModel()
    
    var body: some View {
        ZStack {
            Text("\(item.name)")
                .font(.system(size: 22, weight: .medium))
                .foregroundStyle(.white)
                .padding(.leading, 40)
                .padding(.trailing, 80)
            
            HStack {
                Button {
                    dismiss()
                } label: {
                    Image(systemName: "chevron.left")
                        .font(.system(size: 20, weight: .black))
                        .foregroundStyle(.white)
                }
                .padding(8)
                .background(.ultraThinMaterial)
                .clipShape(Circle())
                
                Spacer()
                
                Button {
                    self.speaker.toggle()
                    // 音量控制通过 VideoSettings 中的 Mute() 处理
                } label: {
                    Image(systemName: speaker ? "speaker.fill" : "speaker.slash.fill")
                        .font(.system(size: 20, weight: .black))
                        .foregroundStyle(.white)
                }
                .padding(6)
                .background(.ultraThinMaterial)
                .clipShape(Circle())
                
                Menu {
                    Button {
                        
                    } label: {
                        Label("稍后播放", systemImage: "plus")
                    }
                    
                    Button {
                        viewModelFav.addToFav(mainId:item.id , type: item.type){ success in
                            if success {
                                print("添加成功")
                            } else {
                                print("添加失败")
                            }
                        }
                    } label: {
                        Label("加入收藏", systemImage: "heart")
                    }
                } label: {
                    Image(systemName: "flag.fill")
                        .font(.system(size: 20, weight: .black))
                        .foregroundStyle(.white)
                        .padding(6)
                        .background(.ultraThinMaterial)
                        .clipShape(Circle())
                }
            }
        }
        .frame(maxWidth: .infinity)
        .frame(height: 30)
        .padding([.horizontal, .bottom])
        .background(.ultraThinMaterial)
      
    }
   
}
